﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Mengoo.DB
{
    /// <summary>
    /// 数据库操作接口
    /// </summary>
    public interface IDBHelper
    {
        /// <summary>
        /// 执行sql语句
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <returns></returns>
        int Execute(string sql);

        /// <summary>
        /// 执行带参数的sql语句
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        int Execute(string sql, params IDataParameter[] cmdParms);

        /// <summary>
        /// 执行事务
        /// </summary>
        /// <param name="sqlList"></param>
        /// <returns></returns>
        int ExecuteTran(List<string> sqlList);

        /// <summary>
        /// 执行sql语句，获取一个DataTable
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <returns></returns>
        DataTable GetDataTable(string sql);

        /// <summary>
        /// 执行sql语句，获取一个DataSet
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <returns></returns>
        DataSet GetDataSet(string sql);

        /// <summary>
        /// 执行一个sql语句，获取一个DataReader
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <returns></returns>
        IDataReader GetDataReader(string sql);

        /// <summary>
        /// 执行一个sql语句，获取记录第一行中的指定字段值
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="field">需要获取的字段值</param>
        /// <returns></returns>
        object ReadField(string sql, string field);

        /// <summary>
        /// 执行一个sql语句，获取记录指定行的指定字段值
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="rowIndex">行数</param>
        /// <param name="field">需要获取的字段值</param>
        /// <returns></returns>
        object ReadField(string sql, int rowIndex, string field);
        
        /// <summary>
        /// 执行存储过程，不带参数
        /// </summary>
        /// <param name="tranName"></param>
        /// <returns></returns>
        DataSet ExecStoredProcedure(string storeName);

        /// <summary>
        /// 执行存储过程，带参数
        /// </summary>
        /// <param name="tranName"></param>
        /// <param name="cmdParams"></param>
        /// <returns></returns>
        DataSet ExecStoredProcedure(string storeName, params IDataParameter[] cmdParams);
    }
}
